﻿using System.Collections;
using System.Collections.Generic;
using LitJson;
using UnityEngine;

public class AddFriendRequest : BaseRequest {
	protected override void Awake()
	{
		_controllerType = ControllerType.USER;
		_methodType = MethodType.ADD_FRIEND;
	
		base.Awake();
	}


	public void SendRequest(int opponentId)
	{
		JsonData requestJsonData = new JsonData();
		requestJsonData["opponentId"] = opponentId;
		NettyRequest nettyRequest = new NettyRequest();
		nettyRequest.controllerType = (int) _controllerType;
		nettyRequest.methodType = (int) _methodType;
		nettyRequest.data = requestJsonData.ToJson();
		byte[] dataBytes = ConverterTool.SerialRequestObj(nettyRequest);
		UnityFacade.Instance.ClientManager.SendMsgToServer(dataBytes);

	}
	
	public override void OnResponse(string data)
	{
		JsonData respJsonData = JsonMapper.ToObject(data);
		MsgPanel msgPanel =(MsgPanel) UnityFacade.Instance.UiManager.PushPanel(PanelType.Msg);
		if (respJsonData["state"].Equals("success"))
		{
			msgPanel.SyncShow("success",respJsonData["msg"].ToString());
			Debug.Log(respJsonData["msg"].ToString());
			
		}else if (respJsonData["state"].Equals("fail"))
		{
			msgPanel.SyncShow("fail",respJsonData["msg"].ToString());
			Debug.LogError(respJsonData["msg"].ToString());
		}
		
		
	}

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}
